package service

import (
	"blog_go/internal/model"
	"blog_go/internal/repository"
	"errors"
)

type ArticleCategoryService interface {
	QueryArticleCategory() ([]*model.ArticleCategory, error)
	AddArticleCategory(categoryName string) error
	UpdateArticleCategory(articleCategory model.ArticleCategory) error
	DelArticleCategory(categoryId int) error
}

type articleCategoryService struct {
	*Service
	articleCategoryRepository repository.ArticleCategoryRepository
}

func NewArticleCategoryService(service *Service, articleCategoryRepository repository.ArticleCategoryRepository) ArticleCategoryService {
	return &articleCategoryService{
		Service:                   service,
		articleCategoryRepository: articleCategoryRepository,
	}
}

// 查询分类
func (s *articleCategoryService) QueryArticleCategory() ([]*model.ArticleCategory, error) {
	return s.articleCategoryRepository.QueryArticleCategory()
}

// 添加分类
func (s *articleCategoryService) AddArticleCategory(categoryName string) error {
	return s.articleCategoryRepository.AddArticleCategory(categoryName)
}

// 更新分类
func (s *articleCategoryService) UpdateArticleCategory(articleCategory model.ArticleCategory) error {
	return s.articleCategoryRepository.UpdateArticleCategory(articleCategory)
}

// 删除分类
func (s *articleCategoryService) DelArticleCategory(categoryId int) error {
	if categoryId == 0 {
		return errors.New("参数错误")
	}

	return s.articleCategoryRepository.DelArticleCategory(categoryId)
}
